package com.autcar.training.controller;

import com.autcar.training.entity.Goods;
import com.autcar.training.service.GoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.controller
 * @ClassName: GoodsController
 * @Author: YHHHH
 * @Description: 商品控制类
 * @Date: 2020/8/29 17:07
 * @Version: 1.0
 */
@RestController
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    /*
    查询商品
     */
    @GetMapping("/findGoods")
    public List<Goods> findGoods(){
       return goodsService.findAllGoods();
    }

    /*
    删除商品
     */
    @RequestMapping("/deleteGoods/{id}")
    public String deleteGoodsById(@PathVariable("id") Integer id){
        int i = goodsService.deleteGoods(id);
        return null;
    }

    /*
    根据商品名字模糊查询商品
     */
    @RequestMapping("/GoodsFindByName/{name}")
    public List<Goods> findByName(@PathVariable String name){
        List<Goods> byName = goodsService.findByName(name);
        return byName;
    }

    /*
    根据价格区间搜索商品
     */
    @RequestMapping("/GoodsFindByPrice/{low}/{high}")
    public List<Goods> findByPrice(@PathVariable Integer low,@PathVariable Integer high){
        return goodsService.findByPrice(low,high);
    }

    @RequestMapping("/GoodsAdd")
    public String addGoods(@RequestBody Goods goods){
        goodsService.addGoods(goods);
        return null;
    }

    @RequestMapping("/GoodsEdit")
    public String editGoods(@RequestBody Goods goods){
        goodsService.updateGoods(goods);
        return null;
    }

}
